package com.gxa.modules.property.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.property.dto.VisitorToAdd;
import com.gxa.modules.property.dto.VisitorToUpdate;
import com.gxa.modules.property.entity.VisitState;
import com.gxa.modules.property.entity.Visitor;
import com.gxa.modules.property.mapper.VisitorMapper;
import com.gxa.modules.property.service.VisitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class VisitorServiceImpl extends ServiceImpl<VisitorMapper, VisitState> implements VisitorService {

    @Autowired
    private VisitorMapper visitorMapper;

    @Override
    public void add(VisitorToAdd visitorToAdd) {
        this.visitorMapper.add(visitorToAdd);
    }

    @Override
    public void delete(Integer id) {
        this.visitorMapper.delete(id);
    }

    @Override
    public void update(VisitorToUpdate visitorToUpdate) {
        this.visitorMapper.update(visitorToUpdate);
    }

    @Override
    public PageInfo<Visitor> queryVisitorList(Map<String,Object> params) {
        String page1 = (String) params.get("page");
        String limit1 = (String) params.get("limit");
        Integer page = Integer.valueOf(page1);
        Integer limit = Integer.valueOf(limit1);

        //条件查询
        String visitStateId = (String) params.get("visitStateId");
        String visitorName = (String) params.get("visitorName");
        String communityId = (String) params.get("communityId");

        PageHelper.startPage(page,limit);
        List<Visitor> queryVisitorList = visitorMapper.queryVisitorList(visitStateId,visitorName,communityId);
        PageInfo<Visitor> pageInfo = new PageInfo<>(queryVisitorList);
        return pageInfo;
    }
}
